package ciyuan.Item.SkillBook;

import ciyuan.Entity.IceBall.IceBallEntity;
import ciyuan.Item.ItemGroups;
import ciyuan.Item.TypeInterface.SkillBookType;
import ciyuan.Player.Skill.SkillUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;

/**
 * @author 150149
 */
public class ShanBall extends SkillBookType {

    public ShanBall() {
        super(new Properties().tab(ItemGroups.SkillBook));
    }

    @Override
    public void keyDown(PlayerEntity playerEntity) {
        SkillUtils.setSkillColdInterval(playerEntity, this, 12 * 1000);

        if (playerEntity.level.isClientSide) {
            return;
        }
        SkillUtils.THREAD_POOL_EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<3;i++) {
                    IceBallEntity IceBallEntity1 = new IceBallEntity(playerEntity, 0, 0,0,playerEntity.level);
                    IceBallEntity1.moveTo(playerEntity.getX(),playerEntity.getY() + 1,playerEntity.getZ(),0.0F, 0.0F);
                    IceBallEntity1.shootFromRotation(playerEntity,playerEntity.xRot,playerEntity.yRot,0.0F, 1.5F, 0.0F);
                    IceBallEntity1.setOwner(playerEntity);
                    SkillUtils.addEntity(IceBallEntity1,playerEntity.level);

                    IceBallEntity IceBallEntity2 = new IceBallEntity(playerEntity, 0, 0,0,playerEntity.level);
                    IceBallEntity2.moveTo(playerEntity.getX(),playerEntity.getY() + 1,playerEntity.getZ(),0.0F, 0.0F);
                    IceBallEntity2.shootFromRotation(playerEntity,playerEntity.xRot,playerEntity.yRot+30,0.0F, 1.5F, 0.0F);
                    IceBallEntity2.setOwner(playerEntity);
                    SkillUtils.addEntity(IceBallEntity2,playerEntity.level);

                    IceBallEntity IceBallEntity3 = new IceBallEntity(playerEntity, 0, 0,0,playerEntity.level);
                    IceBallEntity3.moveTo(playerEntity.getX(),playerEntity.getY() + 1,playerEntity.getZ(),0.0F, 0.0F);
                    IceBallEntity3.shootFromRotation(playerEntity,playerEntity.xRot,playerEntity.yRot-30,0.0F, 1.5F, 0.0F);
                    IceBallEntity3.setOwner(playerEntity);
                    SkillUtils.addEntity(IceBallEntity3, playerEntity.level);
                    playerEntity.level.playSound(null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.BLAZE_SHOOT, playerEntity.getSoundSource(), 1.0F, 1.0F);
                    SkillUtils.sleep(500);
                }
            }
        });

        SkillUtils.saveSkillCastTime(playerEntity,this);
    }

    @Override
    public String getSkillCastName() {
        return "ShanBall";
    }

    @Override
    public ITextComponent getSkillDescription() {
        return new TranslationTextComponent("ciyuan.skill.desc.7");
    }

    @Override
    public ITextComponent getSkillName() {
        return new TranslationTextComponent("ciyuan.skill.name.7");
    }
}
